home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1995 #5 & #6
/
Amiga Plus CD - 1995 - No. 5 and 6.iso
/
pd
/
netz
/
term
/
extras
/
source
/
term-source.lha
/
SoundPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-16
|
10KB
|
432 lines
/*
** SoundPanel.c
**
** Editing panel for sound configuration
**
** Copyright © 1990-1995 by Olaf `Olsen' Barthel
** All Rights Reserved
*/
#include "termGlobal.h"
enum { GAD_BELL=1,GAD_CONNECT,GAD_DISCONNECT,GAD_GOOD_TRANSFER,
GAD_BAD_TRANSFER,GAD_RING,GAD_VOICE,GAD_ERROR,GAD_PRELOAD,GAD_VOLUME,
GAD_USE,GAD_LOAD,GAD_SAVE,GAD_CANCEL
};
BYTE __regargs
SoundPanel(struct SoundConfig *Config)
{
struct LayoutHandle *Handle;
STATIC struct SoundConfig __far BackupConfig;
CopyMem(Config,&BackupConfig,sizeof(struct SoundConfig));
if(Handle = LT_CreateHandleTags(Window -> WScreen,
LH_LocaleHook, &LocaleHook,
LH_ExitFlush, FALSE,
TAG_DONE))
{
struct Window *PanelWindow;
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
LA_LabelID, MSG_V36_0182,
TAG_DONE);
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_BELL_GAD,
LA_STRPTR, Config -> BellFile,
LA_Chars, 30,
LA_ID, GAD_BELL,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_CONNECT_GAD,
LA_STRPTR, Config -> ConnectFile,
LA_ID, GAD_CONNECT,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_DISCONNECT_GAD,
LA_STRPTR, Config -> DisconnectFile,
LA_ID, GAD_DISCONNECT,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_GOOD_TRANSFER_GAD,
LA_STRPTR, Config -> GoodTransferFile,
LA_ID, GAD_GOOD_TRANSFER,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_BAD_TRANSFER_GAD,
LA_STRPTR, Config -> BadTransferFile,
LA_ID, GAD_BAD_TRANSFER,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_RING_GAD,
LA_STRPTR, Config -> RingFile,
LA_ID, GAD_RING,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_VOICE_GAD,
LA_STRPTR, Config -> VoiceFile,
LA_ID, GAD_VOICE,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_ERROR_NOTIFICATION_SOUND_TXT,
LA_STRPTR, Config -> ErrorNotifyFile,
LA_ID, GAD_ERROR,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, XBAR_KIND,
TAG_DONE);
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, SliderType,
LA_LabelID, MSG_SOUNDPANEL_VOLUME_GAD,
LA_BYTE, &Config -> Volume,
LA_ID, GAD_VOLUME,
LA_Chars, 10,
GTSL_Min, 0,
GTSL_Max, 100,
GTSL_LevelFormat, "%ld%%",
TAG_DONE);
LT_New(Handle,
LA_Type, CHECKBOX_KIND,
LA_LabelID, MSG_SOUNDPANEL_PRELOAD_GAD,
LA_BYTE, &Config -> Preload,
LA_ID, GAD_PRELOAD,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type,VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, XBAR_KIND,
LAXB_FullSize, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,LA_Type,HORIZONTAL_KIND,
LAGR_SameSize, TRUE,
LAGR_Spread, TRUE,
TAG_DONE);
{
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_USE_GAD,
LA_ID, GAD_USE,
LABT_ReturnKey, TRUE,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_LOAD_GAD,
LA_ID, GAD_LOAD,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_SAVE_GAD,
LA_ID, GAD_SAVE,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_CANCEL_GAD,
LA_ID, GAD_CANCEL,
LABT_EscKey, TRUE,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
if(PanelWindow = LT_Layout(Handle,LocaleString(MSG_SOUNDPANEL_SOUND_PREFERENCES_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
LAWN_HelpHook, &GuideHook,
LAWN_Parent, Window,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_DragBar, TRUE,
WA_RMBTrap, TRUE,
WA_Activate, TRUE,
TAG_DONE))
{
struct IntuiMessage *Message;
BOOLEAN Done = FALSE;
ULONG MsgClass,
MsgQualifier;
UWORD MsgCode;
struct Gadget *MsgGadget;
STRPTR DummyChar;
UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
struct FileRequester *FileRequest;
GuideContext(CONTEXT_SOUND);
PushWindow(PanelWindow);
do
{
if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
{
CopyMem(&BackupConfig,Config,sizeof(struct SoundConfig));
break;
}
while(Message = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort))
{
MsgClass = Message -> Class;
MsgQualifier = Message -> Qualifier;
MsgCode = Message -> Code;
MsgGadget = (struct Gadget *)Message -> IAddress;
GT_ReplyIMsg(Message);
LT_HandleInput(Handle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
if(MsgClass == IDCMP_CLOSEWINDOW)
{
CopyMem(&BackupConfig,Config,sizeof(struct SoundConfig));
Done = TRUE;
}
if(MsgClass == IDCMP_GADGETUP)
{
switch(MsgGadget -> GadgetID)
{
case GAD_USE:
LT_UpdateStrings(Handle);
SoundChanged = memcmp(&BackupConfig,Config,sizeof(struct SoundConfig));
Done = TRUE;
break;
case GAD_CANCEL:
CopyMem(&BackupConfig,Config,sizeof(struct SoundConfig));
Done = TRUE;
break;
case GAD_LOAD:
SplitFileName(LastSound,&DummyChar,DummyBuffer);
LT_LockWindow(PanelWindow);
if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_SOUNDPANEL_LOAD_SOUNDS_TXT),DummyBuffer,FilePart(LastSound),DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_LOAD_TXT),TRUE))
{
if(!ReadIFFData(DummyBuffer,Config,sizeof(struct SoundConfig),ID_SOUN))
ShowError(PanelWindow,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
else
{
SoundChanged = FALSE;
strcpy(LastSound,DummyBuffer);
LT_SetAttributes(Handle,GAD_BELL,
GTST_String,Config -> BellFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_CONNECT,
GTST_String,Config -> ConnectFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_DISCONNECT,
GTST_String,Config -> DisconnectFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_GOOD_TRANSFER,
GTST_String,Config -> GoodTransferFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_BAD_TRANSFER,
GTST_String,Config -> BadTransferFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_RING,
GTST_String,Config -> RingFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_VOICE,
GTST_String,Config -> VoiceFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_ERROR,
GTST_String,Config -> ErrorNotifyFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_PRELOAD,
GTCB_Checked,Config -> Preload,
TAG_DONE);
LT_SetAttributes(Handle,GAD_VOLUME,
GTSL_Level,Config -> Volume,
TAG_DONE);
}
FreeAslRequest(FileRequest);
}
LT_UnlockWindow(PanelWindow);
break;
case GAD_SAVE:
LT_UpdateStrings(Handle);
SplitFileName(LastSound,&DummyChar,DummyBuffer);
LT_LockWindow(PanelWindow);
if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_SOUNDPANEL_SAVE_SOUNDS_TXT),DummyBuffer,FilePart(LastSound),DummyBuffer,"#?.prefs",TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT),TRUE))
{
if(!WriteIFFData(DummyBuffer,Config,sizeof(struct SoundConfig),ID_SOUN))
ShowError(PanelWindow,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
else
{
strcpy(LastSound,DummyBuffer);
SoundChanged = FALSE;
}
FreeAslRequest(FileRequest);
}
LT_UnlockWindow(PanelWindow);
break;
default:
if(MsgGadget -> GadgetID >= GAD_BELL && MsgGadget -> GadgetID <= GAD_ERROR)
{
STRPTR Name = (STRPTR)LT_GetAttributes(Handle,MsgGadget -> GadgetID,TAG_DONE);
if(MsgCode == '\r' && Name[0])
{
FindFile(PanelWindow,LT_GetString(Handle,MsgGadget -> GadgetID),NULL);
if(Config -> Volume)
{
struct SoundInfo *SoundInfo;
LT_LockWindow(PanelWindow);
if(SoundInfo = LoadSound(Name,FALSE))
{
PlaySound(SoundInfo);
FreeSound(SoundInfo);
}
LT_UnlockWindow(PanelWindow);
}
}
}
break;
}
}
if(MsgClass == IDCMP_IDCMPUPDATE && MsgGadget -> GadgetID >= GAD_BELL && MsgGadget -> GadgetID <= GAD_ERROR)
{
SplitFileName((STRPTR)LT_GetAttributes(Handle,MsgGadget -> GadgetID,TAG_DONE),&DummyChar,DummyBuffer);
LT_LockWindow(PanelWindow);
if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_SELECT_SOUND_FILE_TXT),DummyBuffer,DummyChar,DummyBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
{
if(DummyBuffer[0])
FindFile(PanelWindow,DummyBuffer,NULL);
LT_SetAttributes(Handle,MsgGadget -> GadgetID,
GTST_String,DummyBuffer,
TAG_DONE);
FreeAslRequest(FileRequest);
}
LT_UnlockWindow(PanelWindow);
}
}
}
while(!Done);
PopWindow();
}
LT_DeleteHandle(Handle);
}
return((BYTE)memcmp(&BackupConfig,Config,sizeof(struct SoundConfig)));
}